return none(result);
}
+#define xspy_set_target_doc "\n" \
+ "Tell xenstore that a domain is targetting another one so it\n" \
+ "should let it tinker with it.\n" \
+ " dom [int] : domain id\n" \
+ " target [int] : domain id of the target\n" \
+ "\n" \
+ "Returns None on success.\n" \
+ "Raises xen.lowlevel.xs.Error on error.\n" \
+ "\n"
+
+static PyObject *xspy_set_target(XsHandle *self, PyObject *args)
+{
+ uint32_t dom;
+ uint32_t target;
+
+ struct xs_handle *xh = xshandle(self);
+ bool result = 0;
+
+ if (!xh)
+ return NULL;
+ if (!PyArg_ParseTuple(args, "ii", &dom, &target))
+ return NULL;
+
+ Py_BEGIN_ALLOW_THREADS
+ result = xs_set_target(xh, dom, target);
+ Py_END_ALLOW_THREADS
+
+ return none(result);
+}
+
#define xspy_resume_domain_doc "\n" \
"Tell xenstore to clear its shutdown flag for a domain.\n" \
"This ensures that a subsequent shutdown will fire the\n" \
XSPY_METH(transaction_start, METH_NOARGS),
XSPY_METH(transaction_end, METH_VARARGS | METH_KEYWORDS),
XSPY_METH(introduce_domain, METH_VARARGS),
+ XSPY_METH(set_target, METH_VARARGS),
XSPY_METH(resume_domain, METH_VARARGS),
XSPY_METH(release_domain, METH_VARARGS),
XSPY_METH(close, METH_NOARGS),
from xen.xend.XendDevices import XendDevices
from xen.xend.XendTask import XendTask
from xen.xend.xenstore.xstransact import xstransact, complete
-from xen.xend.xenstore.xsutil import GetDomainPath, IntroduceDomain, ResumeDomain
+from xen.xend.xenstore.xsutil import GetDomainPath, IntroduceDomain, SetTarget, ResumeDomain
from xen.xend.xenstore.xswatch import xswatch
from xen.xend.XendConstants import *
from xen.xend.XendAPIConstants import *
def storeVm(self, *args):
return xstransact.Store(self.vmpath, *args)
+ def permissionsVm(self, *args):
+ return xstransact.SetPermissions(self.vmpath, *args)
+
def _readVmTxn(self, transaction, *args):
paths = map(lambda x: self.vmpath + "/" + x, args)
paths = map(lambda x: self.vmpath + "/" + x, args)
return transaction.store(*paths)
+ def permissionsVmTxn(self, transaction, *args):
+ paths = map(lambda x: self.vmpath + "/" + x, args)
+ return transaction.set_permissions(*paths)
+
#
# Function to update xenstore /dom/*
#
except RuntimeError, exn:
raise XendError(str(exn))
+ def _setTarget(self, target):
+ assert self.domid is not None
+
+ try:
+ SetTarget(self.domid, target)
+ self.storeDom('target', target)
+ except RuntimeError, exn:
+ raise XendError(str(exn))
+
def _initDomain(self):
log.debug('XendDomainInfo.initDomain: %s %s',
self.native_protocol = channel_details['native_protocol'];
self._introduceDomain()
+ if self.info.target():
+ self._setTarget(self.info.target())
self._createDevices()
vncopts = ""
if passwd:
self.vm.storeVm("vncpasswd", passwd)
+ self.vm.permissionsVm("vncpasswd", { 'dom': self.vm.getDomid(), 'read': True } )
vncopts = vncopts + ",password"
log.debug("Stored a VNC password for vfb access")
else:
env['XAUTHORITY'] = self.xauthority
if self.vncconsole:
args = args + ([ "-vncviewer" ])
+ xstransact.Mkdir("/local/domain/0/device-model/%i" % self.vm.getDomid())
+ xstransact.SetPermissions("/local/domain/0/device-model/%i" % self.vm.getDomid(),
+ { 'dom': self.vm.getDomid(), 'read': True, 'write': True })
log.info("spawning device models: %s %s", self.device_model, args)
# keep track of pid and spawned options to kill it later
self.pid = os.spawnve(os.P_NOWAIT, self.device_model, args, env)
self.vm.storeVm(("image/dmargs", " ".join(self.dmargs)),
("image/device-model", self.device_model),
("image/display", self.display))
+ self.vm.permissionsVm("image/dmargs", { 'dom': self.vm.getDomid(), 'read': True } )
self.vm.storeVm(("rtc/timeoffset", rtc_timeoffset))
+ self.vm.permissionsVm("rtc/timeoffset", { 'dom': self.vm.getDomid(), 'read': True } )
self.apic = int(vmConfig['platform'].get('apic', 0))
self.acpi = int(vmConfig['platform'].get('acpi', 0))
def IntroduceDomain(domid, page, port):
return xshandle().introduce_domain(domid, page, port)
+def SetTarget(domid, target):
+ return xshandle().set_target(domid, target)
+
def GetDomainPath(domid):
return xshandle().get_domain_path(domid)
case XS_ERROR: return "ERROR";
case XS_IS_DOMAIN_INTRODUCED: return "XS_IS_DOMAIN_INTRODUCED";
case XS_RESUME: return "RESUME";
+ case XS_SET_TARGET: return "SET_TARGET";
default:
return "**UNKNOWN**";
}
break;
close(conn->fd);
}
+ if (conn->target)
+ talloc_unlink(conn, conn->target);
list_del(&conn->list);
trace_destroy(conn, "connection");
return 0;
mask &= ~XS_PERM_WRITE;
/* Owners and tools get it all... */
- if (!conn->id || perms[0].id == conn->id)
+ if (!conn->id || perms[0].id == conn->id
+ || (conn->target && perms[0].id == conn->target->id))
return (XS_PERM_READ|XS_PERM_WRITE|XS_PERM_OWNER) & mask;
for (i = 1; i < num; i++)
- if (perms[i].id == conn->id)
+ if (perms[i].id == conn->id
+ || (conn->target && perms[i].id == conn->target->id))
return perms[i].perms & mask;
return perms[0].perms & mask;
do_resume(conn, onearg(in));
break;
+ case XS_SET_TARGET:
+ do_set_target(conn, in);
+ break;
+
default:
eprintf("Client unknown operation %i", in->hdr.msg.type);
send_error(conn, ENOSYS);
/* The domain I'm associated with, if any. */
struct domain *domain;
+ /* The target of the domain I'm associated with. */
+ struct connection *target;
+
/* My watches. */
struct list_head watches;
send_ack(conn, XS_INTRODUCE);
}
+void do_set_target(struct connection *conn, struct buffered_data *in)
+{
+ char *vec[2];
+ unsigned int domid, tdomid;
+ struct domain *domain, *tdomain;
+ if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec)) {
+ send_error(conn, EINVAL);
+ return;
+ }
+
+ if (conn->id != 0 || !conn->can_write) {
+ send_error(conn, EACCES);
+ return;
+ }
+
+ domid = atoi(vec[0]);
+ tdomid = atoi(vec[1]);
+
+ domain = find_domain_by_domid(domid);
+ if (!domain) {
+ send_error(conn, ENOENT);
+ return;
+ }
+ if (!domain->conn) {
+ send_error(conn, EINVAL);
+ return;
+ }
+
+ tdomain = find_domain_by_domid(tdomid);
+ if (!tdomain) {
+ send_error(conn, ENOENT);
+ return;
+ }
+
+ if (!tdomain->conn) {
+ send_error(conn, EINVAL);
+ return;
+ }
+
+ talloc_reference(domain->conn, tdomain->conn);
+ domain->conn->target = tdomain->conn;
+
+ send_ack(conn, XS_SET_TARGET);
+}
+
/* domid */
void do_release(struct connection *conn, const char *domid_str)
{
/* domid */
void do_resume(struct connection *conn, const char *domid_str);
+/* domid, target */
+void do_set_target(struct connection *conn, struct buffered_data *in);
+
/* domid */
void do_get_domain_path(struct connection *conn, const char *domid_str);
ARRAY_SIZE(iov), NULL));
}
+bool xs_set_target(struct xs_handle *h,
+ unsigned int domid, unsigned int target)
+{
+ char domid_str[MAX_STRLEN(domid)];
+ char target_str[MAX_STRLEN(target)];
+ struct iovec iov[2];
+
+ snprintf(domid_str, sizeof(domid_str), "%u", domid);
+ snprintf(target_str, sizeof(target_str), "%u", target);
+
+ iov[0].iov_base = domid_str;
+ iov[0].iov_len = strlen(domid_str) + 1;
+ iov[1].iov_base = target_str;
+ iov[1].iov_len = strlen(target_str) + 1;
+
+ return xs_bool(xs_talkv(h, XBT_NULL, XS_SET_TARGET, iov,
+ ARRAY_SIZE(iov), NULL));
+}
+
static void * single_with_domid(struct xs_handle *h,
enum xsd_sockmsg_type type,
unsigned int domid)
unsigned int domid,
unsigned long mfn,
unsigned int eventchn);
+
+/* Set the target of a domain
+ * This tells the store daemon that a domain is targetting another one, so
+ * it should let it tinker with it.
+ */
+bool xs_set_target(struct xs_handle *h,
+ unsigned int domid,
+ unsigned int target);
+
/* Resume a domain.
* Clear the shutdown flag for this domain in the store.
*/
XS_WATCH_EVENT,
XS_ERROR,
XS_IS_DOMAIN_INTRODUCED,
- XS_RESUME
+ XS_RESUME,
+ XS_SET_TARGET
};
#define XS_WRITE_NONE "NONE"